package com.zhongshu.controller;

import com.zhongshu.common.response.PageUtils;
import com.zhongshu.common.response.R;
import com.zhongshu.entity.TUserEntity;
import com.zhongshu.service.TUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: TUserController
 * @Description: TODO
 * @author: 星~
 * @date: 2021/9/8 0008 上午 11:04
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class TUserController {

    @Autowired
    private TUserService tUserService;


    @GetMapping("findPage")
    public R findPage() {
        Map<String, Object> objectObjectMap = new HashMap<>();
        PageUtils pageUtils = tUserService.queryPage(objectObjectMap);
        return R.ok().put("data", pageUtils);

    }


    @GetMapping("/findAll")
    public R findAll() {
        List<TUserEntity> list = tUserService.findAll();
        return R.ok().put("data", list);
    }


    @CacheEvict(value = "userAll", key = "'findAll'")
    @GetMapping("/flushRedis")
    public R flushRedis() {
        log.info("清除了Redis中 userAll::findALl");
        return R.ok();
    }


}


